class Solution
{
public:
    int maxCoins(vector<int> &piles)
    {
        sort(piles.rbegin(), piles.rend());
        int sum = 0;
        int n = piles.size() / 3;
        for (int i = 0; i < n; ++i)
        {
            sum += piles[2 * i + 1];
        }
        return sum;
    }
};